package com.fary.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fary.entity.PayMerchantInfo;
import com.fary.mapper.PayMerchantInfoMapper;
import com.fary.service.PayMerchantInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PayMerchantInfoServiceImpl implements PayMerchantInfoService {

    @Autowired
    private PayMerchantInfoMapper payMerchantInfoMapper;

    @Override
    @Transactional
    public boolean addPayMerchantInfo(PayMerchantInfo payMerchantInfo) {
        // 默认是未审核状态
        payMerchantInfo.setAuditStatus(0);
        // 商家入驻生成商户id
        payMerchantInfo.setMerchantId(IdUtil.getSnowflakeNextIdStr());// 全局唯一 雪花算法
        return payMerchantInfoMapper.insert(payMerchantInfo) > 0 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public PayMerchantInfo getBySocialCreditCodePayMerchantInfo(String socialCreditCode) {
        QueryWrapper<PayMerchantInfo> payMerchantInfoDOQueryWrapper = new QueryWrapper<>();
        payMerchantInfoDOQueryWrapper.eq("social_credit_code", socialCreditCode);
        PayMerchantInfo payMerchantInfo = payMerchantInfoMapper.selectOne(payMerchantInfoDOQueryWrapper);
        return payMerchantInfo;
    }

    @Override
    public PayMerchantInfo getByMerchantIdInfo(String merchantId) {
        QueryWrapper<PayMerchantInfo> payMerchantInfoDOQueryWrapper = new QueryWrapper<>();
        payMerchantInfoDOQueryWrapper.eq("merchant_id", merchantId);
        PayMerchantInfo payMerchantInfo = payMerchantInfoMapper.selectOne(payMerchantInfoDOQueryWrapper);
        return payMerchantInfo;
    }
}
